﻿SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ARITHABORT ON
GO
SET NUMERIC_ROUNDABORT OFF
GO
SET CONCAT_NULL_YIELDS_NULL ON
GO
SET ANSI_PADDING ON
GO
SET ANSI_WARNINGS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[bhp_GalleryGetAllPhotos]
AS
BEGIN
	
	SELECT DISTINCT
		za.idx,
		za.ctime,
		za.cuser,
		za.del,
		za.identyfikator,
		za.kategoria_zdjecia,
		za.mtime,
		za.muser,
		za.tytul_zdjecia,
		za.zdjecie_name,
		za.zdjecie_size,
		za.zdjecie_hash
	FROM
		ZDJECIA_APARTAMENTOW za
		INNER JOIN TYP_APARTAMENTU_pozostale_zdjecia taz ON za.idx = taz.rel
	WHERE
		za.del = 0
		AND taz.del = 0
	UNION
	SELECT 
		za.idx,
		za.ctime,
		za.cuser,
		za.del,
		za.identyfikator,
		za.kategoria_zdjecia,
		za.mtime,
		za.muser,
		za.tytul_zdjecia,
		za.zdjecie_name,
		za.zdjecie_size,
		za.zdjecie_hash
	FROM
		ZDJECIA_APARTAMENTOW za
		INNER JOIN SYS_GALERIA_HOTELU_zdjecia ghz ON za.idx = ghz.rel
	WHERE
		za.del = 0
		AND ghz.del = 0
	
END

